package micro86.operation;

import micro86.engine.Memory;
import micro86.engine.State;
import micro86.engine.parametres.IntParameter;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

/**
 * (c) Kate Luzhevskaya 2013
 */
public class IntDiv implements IOperation{
    IntParameter source;
    IntParameter destination;

    public IntDiv(IntParameter source, IntParameter destination){
        this.source = source;
        this.destination = destination;
    }

    @Override
    public void execute(State state, Memory memory) throws IOperationException{
        int sourseValue = source.get(state);
        int destinationValue = destination.get(state);
        if (destinationValue == 0) {
            throw new IOperationException("Division by zero!!!");
        }
        else {
            source.set(state, sourseValue/destinationValue);
            try {
                destination.set(state, sourseValue%destinationValue);
            } catch (NotImplementedException e) {}
            state.incIP();
        }
    }
}
